#include "pch.h"

Mat expandImage(const Mat &img) {
    auto w = img.rows, h = img.cols;
    auto size = std::max(w, h);
    auto x = (size - w) / 2, y = (size - h) / 2;
    Mat image = Mat::zeros(Size(size, size), CV_8UC1);
    for (auto i = 0; i < w; ++i) {
        for (auto j = 0; j < h; ++j) {
            image.at<uint8_t>(i + x, j + y) = img.at<uint8_t>(i, j);
        }
    }
    return image;
}

int predictImage(const Mat &img, const fdeep::model &model) {
    Mat image;
    resize(img, image, Size(28, 28));
    auto tensor = fdeep::tensor_from_bytes(image.data, 28, 28, 1);
    auto result = *model.predict({tensor})[0].as_vector();
    auto maxValue = std::max_element(result.begin(), result.end());
    size_t i = 0;
    for (; i < result.size(); ++i) {
        if (result[i] == *maxValue)
            break;
    }
    return i;
}